/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleship.game;

/**
 *
 * @author ali
 */

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
import battleship.board.AbstractBoardSide;
import battleship.board.CannotPlaceShipException;
import battleship.ship.DirectionEnum;
import battleship.ship.Ship1;
import battleship.ship.Ship2;
import battleship.ship.Ship3;
import battleship.ship.Ship4;
import battleship.ship.Ship5;
import util.MsgPrinter;

/**
 *
 * @author ali
 */
public class StatePlayer2PlaceShips extends AbstractState {

    AbstractBoardSide board = Game.getCompPlayer().getBoard();

    @Override
    public void execute() {
        try {
            setShip1();
            setShip2();
            setShip3();
            setShip4();
            setShip5();
            MsgPrinter.print("Ships placed for " + Game.getCompPlayer().getName());
        } catch (IllegalArgumentException ex) {
            ex.printStackTrace();
        } catch (CannotPlaceShipException ex) {
            ex.printStackTrace();
        }
    }

    @Override
    public StateType getNextState() {
        return StatePlayer1Turn.getInstance();
    }

    private void setShip1() throws IllegalArgumentException, CannotPlaceShipException {
        int startX = 0;
        int startY = 0;

        Ship1 ship1 = new Ship1(startX, startY, DirectionEnum.HORIZONTAL);
        board.setShip(ship1, startX, startY);
    }

    private void setShip2() throws IllegalArgumentException, CannotPlaceShipException {
        int startX = 0;
        int startY = 1;

        Ship2 ship2 = new Ship2(startX, startY, DirectionEnum.HORIZONTAL);
        board.setShip(ship2, startX, startY);
    }

    private void setShip3() throws IllegalArgumentException, CannotPlaceShipException {
        int startX = 0;
        int startY = 2;

        Ship3 ship3 = new Ship3(startX, startY, DirectionEnum.HORIZONTAL);
        board.setShip(ship3, startX, startY);
    }

    private void setShip4() throws IllegalArgumentException, CannotPlaceShipException {
        int startX = 0;
        int startY = 3;

        Ship4 ship4 = new Ship4(startX, startY, DirectionEnum.HORIZONTAL);
        board.setShip(ship4, startX, startY);
    }

    private void setShip5() throws IllegalArgumentException, CannotPlaceShipException {
        int startX = 0;
        int startY = 4;

        Ship5 ship5 = new Ship5(startX, startY, DirectionEnum.HORIZONTAL);
        board.setShip(ship5, startX, startY);
    }
}
